/*
 * Copyright 2016 Wealth Inc. All rights reserved.
 */
 package com.wealth.commodity.service.impl;

import java.util.List;

import iaas.enums.YesOrNoEnum;
import iaas.service.impl.BaseServiceImpl;
import iaas.utils.ResultObject;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.wealth.commodity.entity.Goods;
import com.wealth.commodity.entity.Purrestrictions;
import com.wealth.commodity.repository.PurrestrictionsDao;
import com.wealth.commodity.service.IPurrestrictionsService;

/**
 * @author chan
 * @version 1.0
 * @since 1.0
 */
 
@Component
public class PurrestrictionsServiceImpl extends BaseServiceImpl<Purrestrictions> implements IPurrestrictionsService{

	@Autowired
	private PurrestrictionsDao purrestrictionsDao;

	public boolean checkPurRestrictions(Goods goods,Integer amount) {
		if(amount>goods.getPurRestrictionsNum()){
			return false;
		}
		return true;
	}

	//计算购买限额商品的数量
	public int findByMemberIdAndGoodsId(Long memberId, Long goodsId) {
		List<Purrestrictions> list=purrestrictionsDao.findByMemberIdAndGoodsId(memberId, goodsId);
		int amount=0;
		for (int i = 0; i < list.size(); i++) {
			amount+=list.get(i).getAmount();
		}
		return amount;
	}
	
}
